Match composite actions in step-level GitHub Actions recipes - #223
Merged
Conversation
`PinGitHubActionsToSha` and friends were gated on `IsGitHubActionsWorkflow`,
so they only ever ran on `.github/workflows/*.{yml,yaml}` and silently skipped
composite actions, whose steps live in `action.yml` under `runs.steps`.
`IsGitHubActionDefinition` already matched those files, and `ChangeAction`,
`ChangeActionVersion` and `UpgradeOfficialGitHubActions` already OR'd the two
preconditions together. Extract that into
`GitHubActionsPreconditions.workflowOrActionDefinition()` and route every
step-level recipe through it, replacing the inline copies and the private
duplicate in `UpgradeOfficialGitHubActions`.
Most matchers needed no change: the `setup-*` recipes use relative
`..steps[?(@.uses =~ ..)]` paths and `ArtifactSecurity`/`TemplateInjection`
use `$..steps[*]`, both of which already reach `runs.steps`. `SetupJavaCaching`
was the exception, anchored at `$.jobs..steps`; `$..steps` is equivalent for
workflows, since nothing else there has `steps`.
Recipes that read workflow-only keys keep the narrower precondition, as
`action.yml` has no `on:`, `jobs:`, `runs-on:`, `permissions:` or `needs:`.
Also guard `UnpinnedDockerImages` against local Dockerfile builds. A Docker
container action's `runs.image` is often `Dockerfile` or `./path/Dockerfile`,
which has no digest to pin and would otherwise be flagged.
MBoegers
approved these changes
Aug 25, 2026
Contributor
There was a problem hiding this comment.
It makes sense to combine, and a static call saves some char, but its the first time I've seen this pattern in our (java-based) recipes. I wonder if we should introduce this or stick with the ususal patterns..
Replaces the `GitHubActionsPreconditions.workflowOrActionDefinition()` static helper with a named recipe that ORs `IsGitHubActionsWorkflow` and `IsGitHubActionDefinition`. A static method is only reachable from Java, so declarative YAML recipes had no way to express "workflow or action definition" as a precondition; a recipe can be referenced from both. All 21 call sites now pass it to the `Preconditions.check(Recipe, ..)` overload, which is recipe-aware, rather than handing over a bare visitor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recipes like
PinGitHubActionsToShawere gated onIsGitHubActionsWorkflow, so they only ran on.github/workflows/*.{yml,yaml}and silently skipped composite actions, whose steps live inaction.ymlunderruns.steps.IsGitHubActionDefinitionalready matched those files and three recipes already OR'd the two preconditions together, so this extracts that intoGitHubActionsPreconditions.workflowOrActionDefinition()and routes every step-level recipe through it; recipes reading workflow-only keys (on:,jobs:,runs-on:,permissions:,needs:) keep the narrower precondition.Most matchers needed no change, since the
setup-*recipes use relative..steps[?(@.uses =~ ..)]paths andArtifactSecurity/TemplateInjectionuse$..steps[*], both of which already reachruns.steps—SetupJavaCachingwas the exception, anchored at$.jobs..steps, and$..stepsis equivalent for workflows since nothing else there hassteps. This also guardsUnpinnedDockerImagesagainst local Dockerfile builds, as a Docker container action'sruns.imageis oftenDockerfileor./path/Dockerfile, which has no digest to pin and would otherwise be flagged.Tests cover one case per distinct matcher shape rather than one per recipe, plus both branches of the new Dockerfile guard; one existing test in
SetupPythonUpgradePythonVersionTestassertedaction.ymlwas skipped and now points atconfig.yml.